package com.betterjr.modules.notice.dubbo;

import java.util.Map;

import javax.annotation.Resource;

import com.alibaba.dubbo.config.annotation.Service;
import com.betterjr.common.web.AjaxObject;
import com.betterjr.modules.notice.INoticeService;
import com.betterjr.modules.notice.constants.NoticeConstants;
import com.betterjr.modules.notice.entity.Notice;
import com.betterjr.modules.notice.service.NoticeService;
import com.betterjr.modules.notice.service.NoticeWorkbenchService;
import com.betterjr.modules.rule.service.RuleServiceDubboFilterInvoker;

@Service(interfaceClass = INoticeService.class)
public class NoticeDubboService implements INoticeService {
    @Resource
    private NoticeService noticeService;

    @Resource
    private NoticeWorkbenchService noticeWorkbenchService;

    @Override
    public String webQueryUnreadNotice(final Map<String, Object> anParam, final int anFlag, final int anPageNum,
            final int anPageSize) {
        final Map<String, Object> param = RuleServiceDubboFilterInvoker.getInputObj();
        return AjaxObject
                .newOkWithPage("未读公告列表-查询成功", noticeService.queryUnreadNotice(param, anFlag, anPageNum, anPageSize))
                .toJson();
    }

    @Override
    public String webQueryReadNotice(final Map<String, Object> anParam, final int anFlag, final int anPageNum,
            final int anPageSize) {
        final Map<String, Object> param = RuleServiceDubboFilterInvoker.getInputObj();
        return AjaxObject
                .newOkWithPage("已读公告列表-查询成功", noticeService.queryReadNotice(param, anFlag, anPageNum, anPageSize))
                .toJson();
    }

    @Override
    public String webCountUnreadNotice() {
        return AjaxObject.newOk("未读公告数量-查询成功", noticeService.findCountUnreadNotice()).toJson();
    }

    @Override
    public String webFindNotice(final Long anId) {
        return AjaxObject.newOk("公告详情-查询成功", noticeService.findNotice(anId)).toJson();
    }

    @Override
    public String webSetDeletedNotice(final Long anId, final Long anCustNo) {
        return AjaxObject.newOk("设置公告已删除状态-成功", noticeService.saveSetDeletedNotice(anId, anCustNo)).toJson();
    }

    @Override
    public String webSetReadNotice(final Long anId, final Long anCustNo) {
        return AjaxObject.newOk("设置公告已读状态-成功", noticeService.saveSetReadNotice(anId, anCustNo)).toJson();
    }

    @Override
    public String webQueryNotice(final Map<String, Object> anParam, final int anFlag, final int anPageNum,
            final int anPageSize) {
        Map<String, Object> param = RuleServiceDubboFilterInvoker.getInputObj();
        return AjaxObject
                .newOkWithPage("机构发布公告列表查询-成功", noticeService.queryNotice(param, anFlag, anPageNum, anPageSize))
                .toJson();
    }

    @Override
    public String webAddPublishNotice(final Map<String, Object> anParam, final String anTargetCust,
            final String anFileList) {
        Notice notice = RuleServiceDubboFilterInvoker.getInputObj();
        return AjaxObject.newOk("添加发布公告-成功",
                noticeService.addNotice(notice, anTargetCust, anFileList, NoticeConstants.NOTICE_STATUS_PUBLISHED))
                .toJson();
    }

    @Override
    public String webAddStoreNotice(final Map<String, Object> anParam, final String anTargetCust,
            final String anFileList) {
        Notice notice = RuleServiceDubboFilterInvoker.getInputObj();
        return AjaxObject
                .newOk("添加暂存公告-成功",
                        noticeService.addNotice(notice, anTargetCust, anFileList, NoticeConstants.NOTICE_STATUS_STORED))
                .toJson();
    }

    @Override
    public String webSavePublishNotice(final Map<String, Object> anParam, final Long anId, final String anTargetCust,
            final String anFileList) {
        Notice notice = RuleServiceDubboFilterInvoker.getInputObj();
        return AjaxObject.newOk("修改发布公告-成功", noticeService.saveNotice(notice, anId, anTargetCust, anFileList,
                NoticeConstants.NOTICE_STATUS_PUBLISHED)).toJson();
    }

    @Override
    public String webSaveStoreNotice(final Map<String, Object> anParam, final Long anId, final String anTargetCust,
            final String anFileList) {
        Notice notice = RuleServiceDubboFilterInvoker.getInputObj();
        return AjaxObject.newOk("修改暂存公告-成功",
                noticeService.saveNotice(notice, anId, anTargetCust, anFileList, NoticeConstants.NOTICE_STATUS_STORED))
                .toJson();
    }

    @Override
    public String webPublishNotice(final Long anId) {
        return AjaxObject.newOk("发布公告-成功", noticeService.savePublishNotice(anId)).toJson();
    }

    @Override
    public String webCancelNotice(final Long anId) {
        return AjaxObject.newOk("撤销公告-成功", noticeService.saveCancelNotice(anId)).toJson();
    }

    @Override
    public String webDeleteNotice(final Long anId) {
        return AjaxObject.newOk("删除公告-成功", noticeService.saveDeleteNotice(anId)).toJson();
    }

    /** 
     * <p>Overriding Method of webFindNoticeWorkbench</p>  
     * <p>Description: </p> 
     * @param anMap 前端参数
     * @return  未读消息
     * @see com.betterjr.modules.notice.INoticeService#webFindNoticeWorkbench(java.util.Map) 
     * @author xuzx
     * @date 2017年11月24日 下午5:18:58 
     */
    @Override
    public String webFindNoticeWorkbench(final Map<String, Object> anMap) {
        // TODO Auto-generated method stub
        return AjaxObject.newOk("查询平台未读信息成功", noticeWorkbenchService.queryNotice(anMap)).toJson();
    }
}
